var vm = new Vue({
	el: '#app',
	data: {
		items: [],
		loaded: false
	},
	mounted: function() {
		getUser();
	}
});

/**
 * 获取用户信息
 */
function getUser() {
	$.ajax({
		type: "POST",
		url: ip + "platform/user/reacquire.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(data) {
			if(data.statusCode == 0) {
				$("#phone").text((data.result.mobile).replace("+86|", ""));
				$("#userName").text(data.result.userName);
				if(data.result.truename == ""){
					$("#truename").html("<span style='color:red;'>暂未实名</span>");
				}else{
					$("#truename").text(data.result.truename);
				}
			} else if(data.statusCode == 1000) {
				loginError();
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}

/**
 * 退出登录
 */
function signOutLogin() {
	$(".weui-btn").attr("disabled", false);
	$.ajax({
		type: "POST",
		url: ip + "platform/user/serverLogout.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(data) {
			if(data.statusCode == 0) {
				$(".weui-btn").attr("disabled", true);
				localStorage.clear();
				sessionStorage.clear();
				// 清除所有的cookie
				var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
				if(keys) {
					for(var i = keys.length; i--;) {
						document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
					}
				}
				$.toptip("退出登录，并清理缓存成功！", 'success');
				setTimeout(function(){
				       mui.openWindow({
							createNew:true,// 打开并且刷新：true刷新，false不刷新
							show:{
								autoShow:true,
								aniShow:'fade-in',
							},
							url: 'signIn.html',
							id: 'signIn'
						});
					},1000);
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}